import { reqUserAddressList,reqOrderInfo,reqOrderList,reqSubmitOrder } from "@/api"
const actions = {
    // 获取用户信息
    async userAddressList({commit}) {
       let result = await reqUserAddressList()
       // console.log(result);
        if(result.code==200) {
            commit('USERINFOLIST',result.data)
            // console.log(result);
        } else {
            return Promise.reject(new error(result.message))
        }
    },
    // 订单交易信息
    async orderInfo({commit}) {
        let result = await reqOrderInfo()  
        if(result.code == 200) {
            commit('ORDERINFO',result.data)
            console.log(result);
        } else {
            return Promise.reject(new Error(result.data))
        }
    },
    // 个人中心订单列表
    async getOrderList() {
        let result = await reqOrderList()
        console.log(result);
    },
    // 提交订单
    async submitInfo({ commit, state, dispatch }, { tradeNo, data }) {
        //提交订单的时候：返回一个很重要数据->订单ID【这笔交易唯一标识符:付款人、收款人】
        let result = await reqSubmitOrder(tradeNo, data);
        if (result.code == 200) {
            commit('SUBMITINFO', result.data);
            return 'ok';
        } else {
            return Promise.reject(new Error(result.message));
        }
    }
} 

const mutations = {
    // 
    USERINFOLIST(state,userInfoList) {
        state.userInfoList = userInfoList
    },
    ORDERINFO(state,orderInfo) {
        state.orderInfo = orderInfo
    },
    SUBMITINFO(state,payId){
        state.payId = payId;
    }
}

const state = {
    userInfoList:[],
    orderInfo:{},
    payId:''
    // submitOrder:{}
}

const getters = {

}

export default {
    actions,
    mutations,
    state,
    getters
}